package com.kehutong.auth.service;

import com.kehutong.auth.entity.AccountLoginLog;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.mvc.webservice.WebService;
import org.coraframework.orm.jdbc.JdbcSession;

@WebService("/auth/accountLoginLog/service")
public class AccountLoginLogService {
    static final Logger logger = LoggerFactory.getLogger(AccountLoginLogService.class);

    @Inject
    private JdbcSession jdbcSession;

    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
        return jdbcSession.findArray(AccountLoginLog.class)
                .eq(jsonObject, "id", "accountNo")
                .between("createTime", jsonObject, "createTime", "createTime")
                .eq("deleted", false)
                .exe();
    }

    @ReqMapping("/get")
    public Object get(AccountLoginLog accountLoginLog) {
        return accountLoginLog;
    }

    @Bean(newInstance = true, copy = true)
    @ReqMapping("/save")
    public Object save(AccountLoginLog accountLoginLog) {
        jdbcSession.insert(accountLoginLog);
        return Result.success();
    }

    @Bean(copy = true)
    @ReqMapping("/update")
    public Object update(AccountLoginLog accountLoginLog) throws Exception {
        jdbcSession.updateById(accountLoginLog);
        return Result.success();
    }

    @ReqMapping("/delete")
    public Object delete(AccountLoginLog accountLoginLog) {
        accountLoginLog.setDeleted(true);
        jdbcSession.updateById(accountLoginLog);
        return Result.success();
    }

}
